<?php

/**
 * 应用助手函数
 */

function is_logged_in() {
    return isset($_SESSION['user_id']);
}

function require_login() {
    if (!is_logged_in()) {
        header('Location: login.php');
        exit;
    }
}

function current_user_id() {
    return $_SESSION['user_id'] ?? null;
}

function logout() {
    $_SESSION = [];
    session_destroy();
}